/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Dao;

import HibernateConfiguration.HibernateUtil;
import Pojo.Hocsinh;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author XuanHung
 */
public class clsHocSinh {
    public static boolean addNewHocSinh(Hocsinh hs){
        Session ss =  HibernateUtil.getSessionFactory().openSession();
        Transaction tran = null;
        try{
            tran = ss.beginTransaction();
            ss.save(hs);
            tran.commit();
        }
        catch(HibernateException he){
            tran.rollback();
            throw new HibernateException (he.toString());
        }
        finally{
            ss.close();
        }
        return true;
    }
    public static boolean updateHocSinh(Hocsinh hs){
        Session ss = HibernateUtil.getSessionFactory().openSession();
        Transaction tran = null;
        try{
            tran = ss.beginTransaction();
            ss.update(hs);
            tran.commit();
        }
        catch(HibernateException he){
            tran.rollback();
            throw new HibernateException (he.toString());
        }
        finally{
            ss.close();
        }
        return true;
    }
    public static boolean removeHocSinh(Hocsinh hs){
       Session ss = HibernateUtil.getSessionFactory().openSession();
       Transaction tran = null;
       try{
           tran = ss.beginTransaction();
           ss.delete(hs);
           tran.commit();
       }
       catch(HibernateException he){
           tran.rollback();
           throw new HibernateException(he.toString());
       }
        return true;
    }
}
